package com.zw.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zw.entity.SysMenu;
import com.zw.entity.SysRole;
import com.zw.service.SysMenuService;
import com.zw.utils.CopyUtils;
import com.zw.vo.GetAllMenusVO;
import com.zw.vo.GetAllRolesVO;
import com.zw.vo.ResponseVO;
import io.jsonwebtoken.lang.Collections;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 菜单权限表(SysMenu)表控制层
 *
 * @author makejava
 * @since 2025-03-14 17:51:58
 */
@RestController
@RequestMapping("sysMenu")
@Api(value = "菜单信息API", tags = "菜单信息API")
public class SysMenuController {
    /**
     * 服务对象
     */
    @Resource
    private SysMenuService sysMenuService;


    /**
     * 获取菜单列表

     * @return 结果
     */
    @ApiOperation("获取菜单列表")
    @GetMapping("/getAllMenus")
    public ResponseVO<List<GetAllMenusVO>> getAllMenus() {
        try {
            List<GetAllMenusVO> resList = new ArrayList<>();
            List<SysMenu> list = sysMenuService.list(new QueryWrapper<SysMenu>().lambda().eq(SysMenu::getStatus,0));
            if (!Collections.isEmpty(list)){
                resList = CopyUtils.copyList(list,GetAllMenusVO.class);
            }
            return new ResponseVO(resList);
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof RuntimeException){
                throw new RuntimeException(e.getMessage());
            }else {
                throw new RuntimeException("获取菜单列表失败，请联系管理员处理！");
            }
        }
    }


}

